package com.sghd.fight.module.game.core;

import com.sghd.pojo.fight.game.ChessType;
import com.sghd.pojo.fight.game.GridVo;

/**
 * @author frank
 * @date 2018-10-18 16:49
 * @desc
 **/
public class Grid {
    private int index;
    private Chess chess;

    private int state;

    public Grid(int index) {
        this.index = index;
    }

    public ChessType getType() {
        return chess.getType();
    }

    public void setChess(Chess chess) {
        this.chess = chess;
    }

    public Chess getChess() {
        return chess;
    }

    public boolean isEmpty() {
        return chess == null || chess.isEmpty();
    }

    public void swap(Grid targetGrid) {
        Chess temp = chess;
        this.chess = targetGrid.chess;
        targetGrid.chess = temp;
    }

    /**消除棋子*/
    public Chess remove() {
        Chess result = chess;
        chess = null;
        return result;
    }

    public void fill(Chess chess) {
        this.chess = chess;
    }

    public int getIndex() {
        return index;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public Grid copy() {
        Grid grid = new Grid(this.index);
        grid.state = this.state;
        grid.chess = this.chess.copy();
        return grid;
    }

    public GridVo toVo() {
        return GridVo.valueOf(state, chess.toVo());
    }
}
